<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>门票预约</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="{:sysconf('cdn_url')}/ticket/css/reg.css?t=20231028" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="{:sysconf('cdn_url')}/ticket/js/jquery-2.1.3.min.js"></script>

</head>
<body>

<section>
    <h1>门票预约</h1>

    <form>
        <input type="hidden" id="cate_id" value="{$cate_id}">
        <div class="form-group">
            <input type="text" id="name" placeholder="姓名">
            <label for="name">姓名</label>
        </div>
        <div class="form-group">
            <input type="text" id="mobile" maxlength="11" placeholder="手机号码">
            <label for="mobile">手机号码</label>
        </div>
        <div class="form-group">
            <input type="text" id="address" placeholder="联系地址">
            <label for="address">联系地址</label>
        </div>
        <div class="form-group">
            <input type="text" id="cardid" maxlength="18" placeholder="身份证">
            <label for="cardid">身份证</label>
            <!--            <label for="cardid">身份证<span class="error">输入一个有效的电子邮件地址</span></label>-->
        </div>
        <button type="button" onclick="reg()">预约</button>
    </form>
</section>

<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">

</div>


<script>
    function validateIdCard(idCard) {
        // 正则表达式
        var regExp = /^\d{17}[\dXx]$/;
        return regExp.test(idCard);
    }

    function reg() {
        var cate_id = $("#cate_id").val();
        var name = $("#name").val();
        var mobile = $("#mobile").val();
        var cardid = $("#cardid").val();
        var address = $("#address").val();

        if (name == '') {
            alert('姓名不能为空')
            return false;
        } else if (mobile == '') {
            alert('手机号不能为空')
            return false;
        } else if (!/^1[3456789]{1}[0-9]{9}$/.test(mobile) && mobile !== '') {
            alert('请输入正确的手机号')
            return false;
        }else if (address == '') {
            alert('地址不能为空')
            return false;
        } else if (cardid == '') {
            alert('身份证号码不能为空')
            return false;
        }else if (!validateIdCard(cardid)) {
            alert('身份证号码格式不正确')
            return false;
        }

        $.ajax({
            type: "POST",
            dataType: 'json',
            url: "/index/ticket/reg",
            data: {
                cate_id: cate_id,
                name: name,
                mobile: mobile,
                cardid: cardid,
                address: address
            },
            success: function (data) {
                if (data.code == 0) {
                    alert(data.message)
                    self.location = '/index/ticket/myticket?cate_id=' + cate_id;//确定按钮跳转地址

                } else if (data.code == 1) {
                    alert(data.message)
                    return false
                } else {
                    alert(data.message)
                    return false
                }

            }
        });
    }

</script>
{include file="ticket/footer"/}
</body>
</html>
